package com.lazybones.base.engineer.service.google.impl;

import com.lazybones.base.engineer.service.google.IGoogleAuthenticatorService;
import com.lazybones.base.engineer.utils.google.GoogleAuthenticator;
import jakarta.servlet.http.HttpServletResponse;
import org.iherus.codegen.qrcode.SimpleQrcodeGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class GoogleAuthenticatorImpl implements IGoogleAuthenticatorService {
    private final Logger log = LoggerFactory.getLogger(GoogleAuthenticatorImpl.class);
    @Override
    public String getGoogleSecretKey() {
        return GoogleAuthenticator.createSecret();
    }

    @Override
    public void getGoogleQrcode(String name, HttpServletResponse response) {
        String qrCodeText = GoogleAuthenticator.createQrCodeText(getGoogleSecretKey(), name, "");
        try {
            new SimpleQrcodeGenerator().generate(qrCodeText).toStream(response.getOutputStream());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public String getGoogleCode(String secretKey) {
        return null;
    }

    @Override
    public Boolean checkGoogleCode(String secretKey, String code) {
        return null;
    }
}
